﻿using System.ComponentModel;
using System.Windows;
using Microsoft.Win32;

namespace Esponce.Common
{
	public class Settings
	{
		/// <summary>
		/// Gets a value indicating whether a visual is displayed in an application designing environment (e.g. Expression Blend).
		/// </summary>
		public static bool IsDesignMode
		{
			get
			{
				var visual = Application.Current.MainWindow;
				return (visual != null ? DesignerProperties.GetIsInDesignMode(visual) : false);
			}
		}

		/// <summary>
		/// Gets or sets permantently stored API key.
		/// </summary>
		public static string ApiKey
		{
			get
			{
				try
				{
					var key = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Esponce\\API 3.0 Demo");
					var value = key.GetValue("ApiKey") as string;
					return value;
				}
				catch
				{
					return null;
				}
			}
			set
			{
				try
				{
					var key = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Esponce\\API 3.0 Demo");
					if (value == null)
					{
						key.DeleteValue("ApiKey");
					}
					else
					{
						key.SetValue("ApiKey", value, RegistryValueKind.String);
					}
				}
				catch
				{
				}
			}
		}
	}
}
